﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Index_FindParty : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void BtBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("HomePage.aspx");
    }

    protected void BtnPartySearch_Click(object sender, EventArgs e)
    {
        var city = TxtCitynameSearch.Text;
        var zipcode = TxtPostalCodeSearch.Text;

        PartyFinderDBDataContext db = new PartyFinderDBDataContext();

        if (city == "")
        {
            var data = from p in db.Parties
                       where p.ZipCode == Convert.ToInt32(zipcode)
                       orderby p.Date
                       select new { p.Tema, p.Date, p.Street, p.PartyId, Count = p.PartyParticipants.Count()};
            LWSearchlistParty.DataSource = data;
            LWSearchlistParty.DataBind();
            LitSearchingForTxt.Text = "Resultater for postnr: " + zipcode;
            LitSearchingForTxt.Visible = true;
        }

        else if (zipcode == "")
        {
            var data = from p in db.Parties
                       where p.Town == city
                       orderby p.Date
                       select new { p.Tema, p.Date, p.Street, p.PartyId, Count = p.PartyParticipants.Count() };
            LWSearchlistParty.DataSource = data;
            LWSearchlistParty.DataBind();
            LitSearchingForTxt.Text = "Resultater for by: " + city;
            LitSearchingForTxt.Visible = true;
        }
        else if (zipcode == "" & city == "")
        {
        }

        else
        {
            var data = from p in db.Parties
                       where p.Town == city
                       where p.ZipCode == Convert.ToInt32(zipcode)
                       orderby p.Date
                       select new { p.Tema, p.Date, p.Street, p.PartyId, Count = p.PartyParticipants.Count() };
            LWSearchlistParty.DataSource = data;
            LWSearchlistParty.DataBind();
            LitSearchingForTxt.Text = "Resultater for by: " + city + " med postnr: " + zipcode;
            LitSearchingForTxt.Visible = true;
        }
        
    }
}